<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础设置-设置考核标准</title>
    <script src="/scripts/boot.js"></script>
</head>
<body class="bg-white">
<div id="viewForm">
    <!--<div class="title-info mb-20"><span>基本信息</span></div>-->
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>区域
            </td>
            <td class="wpl">
                <input type="hidden" class="mini-hidden" name="id"/>
                <div id="areaItem"></div>
            </td>
            <td class="text-titlebg"><span class="color-red">*</span>项目名称</td>
            <td>
                <select id="itemCombo" name="itemId" class="mini-combobox w250" ajaxType="post" onvaluechanged="view.itemChanged()" textField="name" valueField="id" required="true"  errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
                <!--<input type="text" name="itemId" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>-->
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">组团</td>
            <td>
                <!--emptyText="无"-->
                <select id="groupId" name="groupId" class="mini-combobox w250" emptyText="无" showNullItem="true" nullItemText="无" ajaxType="post" onvaluechanged="view.groupChanged()" textField="groupName" valueField="id" errorMode="none"></select>
            </td>
            <td class="text-titlebg"><span class="color-red">*</span>期区名称</td>
            <td>
                <select id="phaseId" name="phaseId" class="mini-combobox w250" ajaxType="post" onvaluechanged="" textField="phaseName" valueField="id" required="true" errorMode="none"></select>
                <!--<input type="text" name="phaseName" class="mini-textbox w250" errorMode="none" required="true" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>-->
            </td>
        </tr>
        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>楼栋名称</td>
            <td>
                <input type="text" name="buildingName" class="mini-textbox w250" errorMode="none" required="true" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>
            </td>
            <td class="text-titlebg">楼层数</td>
            <td>
                <input id="storiesNum" name="storiesNum" class="mini-spinner w250"  minValue="0" maxValue="100"/><span class="unit-span">层</span>
                <!--<input type="text" name="storiesNum" class="mini-textbox w250" errorMode="none" onvalidation="onSumvalidation" requiredErrorText="请输入" vtype="maxLength:48"/>-->
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">建筑性质</td>
            <td>
                <select id="architecturalNature" name="architecturalNature" class="mini-combobox w250" ajaxType="post" url="/dictionary/listValues?name=architecturalNature" textField="value" valueField="id" errorMode="none"></select>
                <!--<input type="text" name="architecturalNature" class="mini-textbox w250" errorMode="none" onvalidation="onSumvalidation" requiredErrorText="请输入" vtype="maxLength:48"/>-->
            </td>
            <td class="text-titlebg">计划建筑面积</td>
            <td>
                <input id="planBuildingArea" name="planBuildingArea" class="mini-spinner w250"  minValue="0" maxValue="2000000" format="n2" decimalPlaces="2"/><span class="unit-span">㎡</span>
                <!--<input type="text" name="planBuildingArea" class="mini-textbox w250" errorMode="none" onvalidation="onSumvalidation" requiredErrorText="请输入" vtype="maxLength:48"/>-->
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">备注</td>
            <td colspan="3" class="wp">
                <textarea name="remark" class="mini-textarea wtextarea" emptyText="" maxlength=250></textarea>
            </td>
        </tr>
    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
<script type="text/javascript">
    var post_flag,form,state,datas;
    var view = {
        init: function () {
            common.areaItem.init({
                idName:'#areaItem',
                isItem: true
            });
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
        },
        //保存
        save: function () {
            form.validate();
            if (form.isValid() == false) return;
            if (post_flag) return;
            var data = form.getData();//获取表单多个控件的数据
            post_flag = true;
            $.ajax({
                url: (state=="new"?"/Building/add":"/Building/edit?id=" + data.id),
                type: "post",
                data: data,
                success: function (msg) {
                    post_flag = false;
                    CloseWindow("ok");
                },
                error: function (errorMsg) {
                    post_flag = false;
                    var msg  = JSON.parse(errorMsg.responseText);
                    common.prompt(msg.message);
                }
            });
        },
//    数据展示
        SetData: function (data) {
            data = mini.clone(data);
            state = data.state;
            if(data.state=="edit"){
                $.ajax({
                    url:"/Building/info?id=" + data.id,
                    type: "post",
                    success: function (text) {
                        //跨页面传递的数据对象，克隆后才可以安全使用
                        datas = mini.decode(text);   //反序列化成对象
                        form.setData(datas);             //设置多个控件数据
                        mini.get("provinceCombo").setValue(datas.phase.item.tSysNation.parentId);
                        mini.get("provinceCombo").setUrl("/item/getProvinceWithItem");
                        mini.get("cityCombo").setValue(datas.phase.item.tSysNation.id);
                        mini.get("cityCombo").setUrl("/item/getCityWithProvince?provinceId="+datas.phase.item.tSysNation.parentId);
                        mini.get("itemCombo").setValue(datas.phase.item.id);
                        mini.get("itemCombo").setUrl("/item/getItemWithCityId?cityId="+datas.phase.item.tSysNation.id);
                        mini.get("groupId").setValue(datas.phase.group.id);
                        mini.get("groupId").setUrl("/group/getGroupByItemId?itemId="+datas.phase.item.id);
                        mini.get("phaseId").setValue(datas.phase.id);
                        if(!datas.phase.group.id){
                            mini.get("phaseId").setUrl("/phase/findPhaseByItemId?itemId="+datas.phase.id);
                        }else {
                            mini.get("phaseId").setUrl("/phase/findPhaseByGroupId?groupId="+datas.phase.group.id);
                        }
                    }
                });
            }else{
                $('input[name=id]').val("");
            }
        },
        //组团、期区
        itemChanged:function(){
            var itemCombo = mini.get("itemCombo");
            var groupId = mini.get("groupId");
            var phaseId = mini.get("phaseId");
            var id = itemCombo.getValue();
            var idp = groupId.getValue();
            var groupUrl = "/group/getGroupByItemId?itemId=" + id;
            var phaseIdUrl = "/phase/findPhaseByItemId?itemId=" + id;
            groupId.setUrl(groupUrl);
            phaseId.setUrl(phaseIdUrl);
        },
        groupChanged:function(){
            var itemCombo = mini.get("itemCombo");
            var groupId = mini.get("groupId");
            var phaseId = mini.get("phaseId");
            var id = groupId.getValue();
            var idI = itemCombo.getValue();
            if(id==""){
                //组团为空
                var phaseIdUrl = "/phase/findPhaseByItemId?itemId=" + idI;
            }else{
                //选择组团
                var phaseIdUrl = "/phase/findPhaseByGroupId?groupId=" + id;
            }
            phaseId.setUrl(phaseIdUrl);
        }
    };
    view.init();
</script>
</body>
</html>